/*-
 * #%L
 * HAPI FHIR - Repository implementations and utilities
 * %%
 * Copyright (C) 2014 - 2025 Smile CDR, Inc.
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */
package ca.uhn.fhir.repository.impl;

import ca.uhn.fhir.repository.IRepositoryLoader;
import jakarta.annotation.Nonnull;

import static java.util.Objects.*;

/**
 * Simple base class for {@link IRepositoryLoader} implementations that select on the sub-scheme of the URL.
 */
public abstract class BaseSchemeBasedFhirRepositoryLoader implements IRepositoryLoader {
	final String mySubScheme;

	/**
	 * Constructor
	 *
	 * @param theSubScheme The sub-scheme to match against. For example, if the URL is "fhir-repository:ig-filesystem:...",
	 *                     then the sub-scheme is "ig-filesystem".
	 */
	protected BaseSchemeBasedFhirRepositoryLoader(String theSubScheme) {
		mySubScheme = theSubScheme;
	}

	public boolean canLoad(@Nonnull IRepositoryRequest theRepositoryRequest) {
		requireNonNull(theRepositoryRequest);

		return mySubScheme.equals(theRepositoryRequest.getSubScheme());
	}
}
